//
//  ExploitManager.swift
//  Taurine
//
//  Created by CoolStar on 8/20/23.
//  Note from CoolStar: I'm retired from jailbreaking. But if I gotta do one last release to do it right, so be it.
//

import Foundation
import UIKit

class ExploitManager {
    static let shared = ExploitManager()
    
    let exploits = [
        Exploit.cicutaVirosa,
        Exploit.kfdPhysPuppet,
        Exploit.kfdSmith
    ]
    
    lazy var availableExploits: [Exploit] = exploits.filter {
        UIDevice.current.systemVersion >= $0.minVersion &&
        UIDevice.current.systemVersion <= $0.maxVersion
    }
    
    var defaultExploit: Exploit {
        return availableExploits.first ?? .nullExploit
    }
    
    var chosenExploit: Exploit {
        let rawPrefValue = UserDefaults.standard.string(forKey: "exploit")
        return availableExploits.first {
            $0.prefName == rawPrefValue
        } ?? defaultExploit
    }
    
    init() {
        UserDefaults.standard.set(chosenExploit.prefName, forKey: "exploit")
    }
}
